import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * configService.js - 系统配置 service
 * @date: 2018-10-29
 */
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
/**
 * 根据平台级系统配置
 * @param {Number} tenantId 租户 ID
 */

export function queryTenantConfig(_x) {
  return _queryTenantConfig.apply(this, arguments);
}
/**
 * 根据平台级系统配置
 * @param {Object} params 租户 ID
 */

function _queryTenantConfig() {
  _queryTenantConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(organizationId) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/config/").concat(organizationId)));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryTenantConfig.apply(this, arguments);
}

export function updateTenantConfig(_x2) {
  return _updateTenantConfig.apply(this, arguments);
}
/**
 * 当前为租户下查询系统配置
 * @param {Number} tenantId 租户 ID
 */

function _updateTenantConfig() {
  _updateTenantConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    var values, organizationId;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            values = params.values, organizationId = params.organizationId;
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/config/").concat(organizationId), {
              method: 'PUT',
              body: values
            }));

          case 2:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _updateTenantConfig.apply(this, arguments);
}

export function queryOrganizationConfig(_x3) {
  return _queryOrganizationConfig.apply(this, arguments);
}
/**
 * 当前为租户下更新系统配置
 * @param {Object} params 更新参数，包含租户 id
 */

function _queryOrganizationConfig() {
  _queryOrganizationConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(organizationId) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/config")));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _queryOrganizationConfig.apply(this, arguments);
}

export function updateOrganizationConfig(_x4) {
  return _updateOrganizationConfig.apply(this, arguments);
}

function _updateOrganizationConfig() {
  _updateOrganizationConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    var values, organizationId;
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            values = params.values, organizationId = params.organizationId;
            return _context4.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/config"), {
              method: 'PUT',
              body: values
            }));

          case 2:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _updateOrganizationConfig.apply(this, arguments);
}